
// 一对多的数据
let obj = [
    { name: '辣椒炒肉', classify: '天天神券' },
    { name: '炒青菜', classify: '满减商家' },
    { name: '芋头牛肉', classify: '会员商家' },
    { name: '剁椒鱼头', classify: '优惠商家' },
    { name: '印度飞饼', classify: '满减商家' },
    { name: '爆炒猪肝', classify: '天天神券' },
]
let classifylist = obj.reduce((group, item) => {
    let newkey = item['classify']
    if (!group[newkey]) {
        group[newkey] = []
    }
    group[newkey].push(item)
    return group
}, [])
// console.log(classifylist)

// 多对多
let obj1 = [
    {name: '辣椒炒肉', classify: ['天天神券', '满减商家', '会员商家']},
    {name: '炒青菜', classify: ['满减商家', '满减商家']},
    {name: '芋头牛肉', classify: ['会员商家', '优惠商家']},
    {name: '剁椒鱼头', classify: ['优惠商家', '天天神券', '满减商家', '会员商家']},
    {name: '印度飞饼', classify: ['满减商家', '优惠商家']},
    {name: '爆炒猪肝', classify: ['天天神券', '满减商家']},
  ]

let list = obj1.reduce((pre, item) => {
    let flag = item
    item.classify.forEach(item => {
        if(!pre[item]) {
            pre[item] = []
        }
        pre[item].push(flag)
    })
    return pre
}, []) 

console.log(list)